﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Globalization;
using System.Data;

public partial class companypart_SubsReports : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected override void InitializeCulture()
    {
        if (Session["CurrentCulture"] != null)
        {
            string lang = Session["CurrentCulture"].ToString();
            if (lang != null && lang != "")
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
                Thread.CurrentThread.CurrentCulture.DateTimeFormat = new CultureInfo("en-US", false).DateTimeFormat;
                // Thread.CurrentThread.CurrentCulture.Calendar=new  System.Globalization.GregorianCalendar();

            }
        }
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {

        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    e.Row.Attributes.Add("onmouseover", "this.Mystyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFA8'");

        //    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.Mystyle");
        //}
    }
    protected void aore_Click(object sender, EventArgs e)
    {
        //ToolTip='<%# String.Format("{0} , {1}", Eval("id"), Eval("enddate")) %>'
        LinkButton lk = (LinkButton)sender;
        string[] bb = lk.ToolTip.Split(',');//[0];
        DataSet ds = DB.getproc("getstats", "@id," + bb[0]);

        if (ds.Tables[0].Rows.Count == 2)
        {
            DataRow dr = ds.Tables[0].Rows[0];

            DataRow dr2 = ds.Tables[0].Rows[1];

            //decimal arrv = decimal.Parse(bb[1]) * int.Parse( dr["received"].ToString());
            //decimal noarrv = decimal.Parse(bb[1]) * int.Parse(dr2["received"].ToString());

            arrive.Text = dr2["received"].ToString();//arrv.ToString() ;
            arriveprice.Text = dr2["total"].ToString();//(arrv * decimal.Parse(bb[2])).ToString();
            noarrive.Text = dr["received"].ToString();// noarrv.ToString();
            noarriveprice.Text = dr["total"].ToString(); //(noarrv * decimal.Parse(bb[2])).ToString();
        }
        else if (ds.Tables[0].Rows.Count == 1)
        {
            DataRow dr = ds.Tables[0].Rows[0];
            if (ds.Tables[0].Rows[0]["delivered"].ToString() == "1")
            {
                arrive.Text = dr["received"].ToString();
                arriveprice.Text = dr["total"].ToString();
                noarrive.Text = "0";
                noarriveprice.Text = "0";
            }
            else
            {
                arrive.Text = "0";
                arriveprice.Text = "0";
                noarrive.Text = dr["received"].ToString();
                noarriveprice.Text = dr["total"].ToString();
            }

        }
        else
        {
            arrive.Text = "0";
            arriveprice.Text = "0";
            noarrive.Text = "0";
            noarriveprice.Text = "0";
        }
        detail.Visible = true;
    }

    protected void selectall_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow dr in GridView1.Rows)
        {

            CheckBox chk = (CheckBox)dr.FindControl("chkAdd");
            chk.Checked = true;

        }

    }
    protected void deselectall_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow dr in GridView1.Rows)
        {

            CheckBox chk = (CheckBox)dr.FindControl("chkAdd");
            chk.Checked = false;

        }
    }
    protected void genreport_Click(object sender, EventArgs e)
    {
        string myval = "";
        foreach (GridViewRow dr in GridView1.Rows)
        {
            CheckBox chk = (CheckBox)dr.FindControl("chkAdd");
            if (chk.Checked)
            {
                myval += chk.ToolTip + ",";
            }

        }
        myval = myval.Trim(",".ToCharArray()[0]);


        Response.Redirect("~/reps2.aspx?rep=" + "CompnySubs" + "&id=" + Session["company_id"].ToString() + "&sid=" + myval + "&did=" + Session["company_id"]);


    }   

}
